package vip.meeet.thread.pool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * https://mp.weixin.qq.com/s?__biz=MzIyNDU2ODA4OQ==&mid=2247484554&idx=1&sn=6327c07445a24233d464429dd7debcfb&chksm=e80db2fcdf7a3bea34e6f6a94724fe9a3cc3575fd8dd47bb4611a2361b05dd500cc3a204e5ba&scene=21#wechat_redirect
 * https://mp.weixin.qq.com/s?__biz=MzIyNDU2ODA4OQ==&mid=2247484281&idx=1&sn=83907db106b6d771216b212e46becdd9&chksm=e80db50fdf7a3c194d27386faaca61afc06a679ea06ecaeb9e303121c0312d451d41c3d1a5cf&scene=21#wechat_redirect
 */
public class ThreadPoolExecutorStart {

    public static void main(String[] args) {


    }

    /**
     * 延迟执行的线程池
     */
    private static void newScheduleThreadPoolTest(){
        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(5);
        scheduledThreadPool.schedule(new Runnable() {
            public void run() {
                System.out.println("delay 3 seconds");
            }
        }, 3, TimeUnit.SECONDS);
    }

    private void doc(){
        /**
         * maximumPoolSize:Interger. MAX_VALUE,基本就是工作线程无限制
         * 线程存活60s
         * SynchronousQueue：take和put配对，如果没有配对则阻塞
         * 内存可能会被打爆
         */
        Executors.newCachedThreadPool();


        /**
         * LinkedBlockingQueue:固定大小队列corePoolSize == maximumPoolSize,所以线程池中会保留固定数量
         */
        Executors.newFixedThreadPool(5);

        //线程数量为1的fixed特殊情况
        Executors.newSingleThreadExecutor();

    }
}
